#include<bits/stdc++.h>
using namespace std;
#define f(a,b,c,d) for(int a=b;a<=c;a+=d)
int L,V,p[1000100],T,n,m,cnt;
struct car{
	int d,v,a,l,r;
	bool f;
}c[100100];
void cac(int i,int d,int v,int a,int l,int r,bool f){
	if(a<=0 and v<=V) l=-1,r=-1;
	else if(a>=0 and v>V) l=d,r=L;
	else if(a>0 and v<=V) l=d+(V*V-v*v)/(2*a),r=L,l+=(l==r?0:1);
	else if(a<0 and v>=V) l=d,r=d+(V*V-v*v)/(2*a),r-=(l==r?0:1);
	c[i].d=d; c[i].v=v; c[i].a=a; c[i].l=l; c[i].r=r;;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		memset(p,0,sizeof p); cnt=0;
		scanf("%d%d%d%d",&n,&m,&L,&V);
		f(i,1,n,1){
			scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);
			cac(i,c[i].d,c[i].v,c[i].a,c[i].l,c[i].r,c[i].f);
		}
		f(i,1,m,1){
			int x; scanf("%d",&x);
			p[x]=1;
		}
		f(i,2,L,1) p[i]=p[i-1]+p[i];
		f(i,1,n,1) if(p[c[i].r]-p[c[i].l-1]>0) cnt++,c[i].f=p[c[i].r]-p[c[i].l-1];
		memset(p,0,sizeof(p));
		f(i,1,n,1) if(c[i].f!=0){
			if(p[c[i].r]-p[c[i].l-1]==0){
				f(j,c[i].l,c[i].r,1) p[j]=1;
				f(j,1,c[i].r,1) p[j]+=p[j-1];
				f(j,c[i].r+1,L,1) p[j]+=c[i].r-c[i].l+1;
			}
		}
		int k=1,ks=0; p[0]=p[1];
		f(i,1,L,1){
			if(p[i]-p[i-1]==0) k=0;
			else if(p[i]-p[i-1]!=0 and k==0) ks++,k=1;
		}
		printf("%d %d\n",cnt,n-ks);
	}
	return 0;
}
